//category页面初始化函数
function categoryInit(){
    showItem('cat-tab');
}

function showItem(id)
{
    var categoryIds

    if(id === 'cat-tab') categoryIds = 'cat'
    if(id === 'dog-tab') categoryIds = 'dog'
    if(id === 'bird-tab') categoryIds = 'bird'
    if(id === 'bugCat-tab') categoryIds = 'bugCat'
    if(id === 'pokemon-tab') categoryIds = 'pokemon'
    $.ajax
    (
        {
            type:'GET',
            url:'http://localhost:8022/itemGet?categoryId=' + categoryIds,
            success: function (data)
            {
                var appendHtml = ''
                var selectId = '#'+categoryIds+'_cardArea'
                $(selectId).empty();
                console.log('selectId = ' + selectId)
                var datajosn = JSON.parse(data)
                console.log(datajosn)
                var limitsNum = '';
                for(var i in datajosn){
                    if(datajosn[i].limits==='0'){
                        limitsNum = '无限制';
                    }else{
                        limitsNum = datajosn[i].limits
                    }

                    appendHtml += "<!--上架商品卡片开始--><div class=\"card border rounded-3 border-success mx-3 my-3\"style=\"width: 13vw; float: left;\" id=\""+pinyin.getFullChars(datajosn[i].name)+"_card"+"\">"
                    +"<!--商品的图片-->"+
                    "<img id=\""+ pinyin.getFullChars(datajosn[i].name)+"_image"+"\" decoding=\"async\" class=\"card-img-top\"style=\"max-width: 13vw; height: 29vh;\" src=\""+ "http://localhost:8022" +datajosn[i].description+"\">"+
                    "<!--商品的信息-->"+
                    "<div class=\"card-body\">"+
                    "<h5 class=\"card-title\" id=\""+pinyin.getFullChars(datajosn[i].name)+"\""+">"+datajosn[i].name+"</h5>"+
                    "<p class=\"card-text small lh-1\" id=\""+pinyin.getFullChars(datajosn[i].name)+"_states"+"\""+">商品状态:"+datajosn[i].states+"</p>"+
                    "<p class=\"card-text small lh-1\" id=\""+pinyin.getFullChars(datajosn[i].name)+"_limits"+"\""+">商品限购:"+limitsNum+"</p>"+
                        "<p class=\"card-text small lh-1\" id=\""+pinyin.getFullChars(datajosn[i].name)+"_price"+"\""+">价格:"+datajosn[i].unitPrice+"</p>"+
                    "<p class=\"card-text small lh-1\" id=\""+pinyin.getFullChars(datajosn[i].name)+"_number"+"\""+">商品库存:"+datajosn[i].quantity+"</p><div class=\"row px-2\"><div class=\"col-md-6 text-center\">"+
                    "<button type=\"button\" class=\"btn btn-primary\" data-bs-toggle=\"modal\"data-bs-target=\"#editItem\" onclick=\"setCurrentItem('"+pinyin.getFullChars(datajosn[i].name)+"')"+"\">编辑</button>"+
                    "</div>"+
                    "<div class=\"col-md-6 text-center\">"+
                    "<button type=\"button\" class=\"btn btn-danger\" data-bs-toggle=\"modal\"data-bs-target=\"#takeDownItem\" onclick=\"setCurrentItem('"+pinyin.getFullChars(datajosn[i].name)+"')"+"\">下架</button>"+
                    "</div>"+
                    "</div>"+
                    "</div>"+
                    "</div>"+
                    "<!--上架商品卡片结束-->"
                }
                $(selectId).append(appendHtml)

            },
            error:function (errorMsg)
            {
                console.log("fail")
                console.log(errorMsg)
            },
        }
    )
}